package com.yuanian.timingwheel.test;

import com.yuanian.timingwheel.annotation.TaskHandler;
import com.yuanian.timingwheel.annotation.TimingTask;
import com.yuanian.timingwheel.model.task.build.TaskExecutionBuilder;
import com.yuanian.timingwheel.model.task.build.adapter.FixedDateTaskExecutionAdapter;
import com.yuanian.timingwheel.model.task.build.adapter.ImmediateTaskExecutionAdapter;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;
import java.util.Random;

//@TaskHandler
public class CommonService implements Serializable {

    @TimingTask(dynamicParamSolver = "dynamicSolver1")
    public void run(Teacher teacher, Teacher teacher1) {
        try {
            Thread.sleep(new Random().nextInt(1));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("-------run----------" + teacher.getName() + "|||||||" + teacher1.getName() + ":" + teacher.getList().size());
        for (String s : teacher.getList()) {
            System.out.println("-------run----------" + s);
        }
    }

    public void run1() {
        System.out.println("-------run1----------");
    }

    @TimingTask(dynamicParamSolver = "dynamicSolver1")
    public void run2(Teacher teacher, Teacher teacher1) {

    }

    public TaskExecutionBuilder dynamicSolver1(Teacher teacher, Teacher teacher1) {
        return new ImmediateTaskExecutionAdapter() {

            @Override
            public String taskDesc() {
                return "test";
            }

            @Override
            public String businessId() {
                return "test01";
            }
        };
    }

    public TaskExecutionBuilder dynamicSolver2(Teacher teacher, Teacher teacher1) {
        return new FixedDateTaskExecutionAdapter() {

            @Override
            public Date executionTime() {
                return new Date();
            }

            @Override
            public String taskDesc() {
                return "test";
            }

            @Override
            public String businessId() {
                return "test01";
            }


        };
    }

}
